﻿using Hospital.IRepository;
using Hospital.IService;
using Hospital.Model.Page;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Hospital.Service
{
    /// <summary>
    /// 业务层调用封装的仓储层的基础方法去实现复杂业务
    /// </summary>
    /// <typeparam name="TEntiry"></typeparam>
    public class BaseService<TEntiry> : IBaseService<TEntiry> where TEntiry : class, new()
    {
        protected IBaseRepository<TEntiry> _iBaseRepository;
        //创建表业务
        public async Task<bool> CreateAsync(TEntiry entiry)
        {
            return await _iBaseRepository.CreateAsync(entiry);
        }
        public async Task<bool> DeleteAsync(int id)
        {
            return await _iBaseRepository.DeleteAsync(id);
        }
        public async Task<int> DeleteAsync(List<int> ints)
        {
            return await _iBaseRepository.DeleteAsync(ints);
        }
        public async Task<bool> EditAsync(TEntiry entiry)
        {
            return await _iBaseRepository.EditAsync(entiry);
        }
        public async Task<bool> EditAsync(Expression<Func<TEntiry, TEntiry>> columns, Expression<Func<TEntiry, bool>> func)
        {
            return await _iBaseRepository.EditAsync(columns, func);
        }
        public async Task<int> EditAsync(TEntiry entiry, Expression<Func<TEntiry, bool>> func)
        {
            return await _iBaseRepository.EditAsync(entiry, func);
        }
        public async Task<TEntiry> FindAsync(int id)
        {
            return await _iBaseRepository.FindAsync(id);
        }
        public async Task<List<TEntiry>> QueryAsync()
        {
            return await _iBaseRepository.QueryAsync();
        }
        public async Task<List<TEntiry>> QueryAsync(Expression<Func<TEntiry, bool>> func)
        {
            return await _iBaseRepository.QueryAsync(func);
        }
        public async Task<List<TEntiry>> QueryAsync(int page, int size, RefAsync<int> total)
        {
            return await _iBaseRepository.QueryAsync(page, size, total);
        }

        public async Task<List<TEntiry>> QueryAsync(Expression<Func<TEntiry, bool>> func, int page, int size, RefAsync<int> total)
        {
            return await _iBaseRepository.QueryAsync(func, page, size, total);
        }

        public async Task<List<TEntiry>> QueryAsync(PageRequest pageRequest, RefAsync<int> total)
        {
            return await _iBaseRepository.QueryAsync(pageRequest, total);
        }

        public async Task<TEntiry> FindAsync(Expression<Func<TEntiry, bool>> func)
        {
            return await _iBaseRepository.FindAsync(func);
        }

        public async Task<List<dynamic>> QueryAsyncDynamic()
        {
            return await _iBaseRepository.QueryAsyncDynamic();
        }

        public async Task<List<dynamic>> QueryAsync(Expression<Func<TEntiry, dynamic>> expression, Expression<Func<TEntiry, bool>> func)
        {
            return await _iBaseRepository.QueryAsync(expression, func);
        }

    }
}
